<template>
  <!-- row-key="id"：展示树形结构数据
  default-expand-all：默认展示所有数据
   -->
  <el-table :data="get_menuList" border style="width: 100%" row-key="id" default-expand-all>
    <el-table-column prop="id" label="菜单编号" width="180"></el-table-column>
    <el-table-column prop="title" label="菜单名称" width="180"></el-table-column>
    <el-table-column prop="pid" label="上级菜单"></el-table-column>
    <el-table-column prop="icon" label="菜单图标"></el-table-column>
    <el-table-column prop="url" label="菜单地址"></el-table-column>
    <el-table-column prop="status" label="状态">
      <template v-slot="item">
        <span v-if="item.row.status == 1"><el-button type="primary" plain size="small">启用</el-button></span>
        <span v-else> <el-button type="primary" plain>禁用</el-button></span>
      </template>
    </el-table-column>
    <el-table-column label="操作">
      <template v-slot="item">
        <!-- {{ item.row.id }} -->
        <el-button type="primary" size="small" @click="editItem(item.row.id)">编辑</el-button>
      <el-button type="danger" size="small" @click="delItem(item.row.id)">删除</el-button>
      </template>
    </el-table-column>
  </el-table>
</template>

<script>
import {menudelete} from "@/request/api.js"
import { mapGetters, mapActions } from "vuex";
export default {
  data() {
    return {};
  },
  computed: {
    ...mapGetters({
      get_menuList: "menu/get_menuList"
    })
  },
  methods: {
    ...mapActions({
      action_menuList: "menu/action_menuList"
    }),
    //删除
    delItem(id){
      //询问
      this.$confirm('此操作将永久删除该菜单, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(async () => {

          //发起请求
           try{
            //根据菜单id删除的对应数据
            let res = await menudelete({id});
            if(res.code == 200){
              //提示成功
              this.$message.success(res.msg);
              //重新获取数据库中的数据  请求
              this.action_menuList();

            }else{
              this.$message.error(res.msg)  
            }
           }catch(err){
            this.$message.error(err)  
           }




        }).catch(() => {
          this.$message.info("取消删除")     
        });
    },
    //编辑
    editItem(id){
      this.$emit("edit",id);
    }
  },
  mounted() {
    //页面一加载就去请求数据
    this.action_menuList();
  }
};
</script>

<style>
</style>